package com.shujia;

import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import java.io.*;
import java.util.Map;
import java.util.Set;

public class GetData {
    public static void main(String[] args) throws IOException, InterruptedException {
        System.setProperty("webdriver.edge.driver","E:\\workspace\\ideaProjects\\bigdata27-mypro\\redis-jedis\\src\\main\\resources\\msedgedriver.exe");
        System.out.println(System.getProperty("webdriver.edge.driver"));
        WebDriver edgeDriver = new EdgeDriver();
        edgeDriver.get("https://www.jd.com");
        Thread.sleep(50000);
        Set<Cookie> cookies = edgeDriver.manage().getCookies();
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("redis-jedis/src/main/resources/cookie.txt", true));
        for (Cookie cookie : cookies) {
            Map<String, Object> cookieJson = cookie.toJson();
            for (String key : cookieJson.keySet()) {
                bufferedWriter.write(key +"="+ cookie.toJson().get(key));
                bufferedWriter.newLine();
                bufferedWriter.flush();
            }
        }
        System.out.println("=================================================");
        bufferedWriter.close();
    }
}
